Skip to content

fix: allow first-time HODLMM deposit bins#583

Open
macbotmini-eng wants to merge 1 commit into
BitflowFinance:mainfrom
macbotmini-eng:macbotmini-eng/fix-hodlmm-deposit-first-time-bins
Open

fix: allow first-time HODLMM deposit bins#583
macbotmini-eng wants to merge 1 commit into
BitflowFinance:mainfrom
macbotmini-eng:macbotmini-eng/fix-hodlmm-deposit-first-time-bins

Conversation

@macbotmini-eng
Copy link
Copy Markdown
Contributor

@macbotmini-eng macbotmini-eng commented May 5, 2026

Summary

Fixes the first-time HODLMM deposit path for bitflow-hodlmm-deposit.

The skill documentation says first-time deposits into valid protocol bins are supported, but the live Bitflow user-bin endpoint currently returns HTTP 404 when the wallet has no existing pool bins. That observed response should mean "no existing wallet position yet," not "the pool is unusable," after the separate pool and bin metadata checks pass.

API surface check

Live spec checked: https://bff.bitflowapis.finance/api/app/openapi.json

  • Spec identity: BFF API 1.0.0, OpenAPI 3.1.0.
  • /api/app/v1/pools/{pool_id} is documented as Get Pool By Id: pool metadata by pool id.
  • /api/app/v1/pools is documented as pool listing/filtering metadata.
  • /api/app/v1/users/{user_address}/positions/{pool_id}/bins is documented as Get User Pool Bins: bin information for a specific user and pool, with fresh=true support and user-position cache/fallback headers.
  • The user-bin operation documents 200 and 422 responses; it does not document 404 as a pool-existence signal.

That split is the behavior this PR codifies: pool validity comes from pool/bin metadata checks, while the user-bin endpoint is wallet-specific position state. A missing user-position row for a wallet with no existing bins is not enough to reject a first-time deposit when the pool metadata and protocol-bin data are valid.

Quote-side cross-check: https://bff.bitflowapis.finance/api/quotes/openapi.json documents /api/quotes/v1/bins/{pool_id} as pool bin reserves, prices, and liquidity information, which is the protocol-bin side of the same separation.

Change

  • Treat the specific HTTP 404 ... has no pool bins user-position response as an empty wallet-bin set.
  • Preserve all other 404s and API failures as errors.
  • Leave selected protocol-bin validation, token balance checks, postconditions, and deny-mode transaction safety unchanged.

Validation

Pre-proof route validation, before the #559 route consumed the funded sBTC:

  • bun run skills/bitflow-hodlmm-deposit/bitflow-hodlmm-deposit.ts status --wallet SP2G6TM8JCRNK6WSPQE8S86FP2W3A4FEVGZCCCQT8 --pool-id dlmm_1 --amount-x 4300 --amount-y 0
    • returned success
    • selected active bin 700
    • reported hasExistingPosition: false
    • postcondition mode remained deny
    • postconditions included wallet sends <= 4300 sBTC

Current live reruns with the same 4300 amount now correctly block on insufficient sBTC because that balance was used by the #559 proof route. The important behavior from this PR remains verified: the specific first-time has no pool bins API response no longer stops planning before pool/bin metadata, token balance, and postcondition checks run.

Additional checks:

  • GitHub Actions posted validation passed for bitflow-hodlmm-deposit with 0 errors and 0 warnings.
  • bun run scripts/validate-frontmatter.ts
    • bitflow-hodlmm-deposit passed with 0 errors and 0 warnings
    • full repo validation still reports pre-existing unrelated failures in dca, stacking-delegation, and zest-yield-manager
  • git diff --check
    • passed

Why this matters

This is required for composed routes like #559 where the first route proof starts from idle sBTC and creates the wallet's first HODLMM position in an existing pool/bin.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 5, 2026

✅ Validation Passed

Skill: bitflow-hodlmm-deposit
Errors: 0
Warnings: 0

All checks passed. This submission is ready for review.

biwasxyz added a commit to aibtcdev/skills that referenced this pull request May 26, 2026
… user-bins 404 (#397)

* fix(bitflow-hodlmm-deposit): allow first-time deposit by handling BFF user-bins 404

`getUserBins` calls `fetchJson` with no error handling. BFF returns HTTP 404
with detail "Pool {pool} not found or user {addr} has no pool bins" when a
wallet has zero existing LP positions in the pool. That is the normal
first-time deposit case (explicitly supported per SKILL.md), not an error,
but the throw bubbles up and crashes `doctor`, `status`, and `run` before
any deposit logic executes.

Wrap the fetch in try/catch. Catch ONLY the specific
`HTTP 404 from ... has no pool bins` response shape and return an empty
bins array. Let any other 404 or API failure propagate unchanged. Downstream
code at line 498+ already handles an empty `bins` array correctly via
`.filter(b => b.userLiquidity > 0n)` — empty array is the right shape for
postcondition-plan adjustment to treat the wallet as a new LP.

Companion fix to staging PR BitflowFinance/bff-skills#583
which patches the same bug in the staging copy of this skill.

Verified end-to-end on Stacks mainnet against three wallet shapes:

- Fresh wallet `SP3YWTZQQ7ZYHG1ECEG6AJAT4KX36W2NA7Q6TCKBG` (was failing):
  doctor and status both now succeed; status preview generates full deposit
  plan (activeBin 648, 3-bin equal-split, slippage-protected minDlp,
  bounded postcondition).
- Wallet with existing positions `SP2G6TM8JCRNK6WSPQE8S86FP2W3A4FEVGZCCCQT8`:
  doctor still works (no regression).
- Wallet with positions in OTHER pools but not this one
  (`SP2G6TM8...` + `--pool-id dlmm_9`): correctly handled as first-time.

Verified across dlmm_1, dlmm_3, dlmm_7 pools. `bun run typecheck` passes.

* docs(bitflow-hodlmm-deposit): note fetchJson error-format coupling in 404 catch

Add a comment flagging that the empty-state catch is coupled to fetchJson's
internal error message format ("HTTP 404 from ..."). If fetchJson's format
ever changes, the catch silently fails — the 404 propagates instead of
returning [], which is safe (no data loss) but the fix stops working with no
diagnostic signal. The note tells a future fetchJson refactor where to look.

Comment-only change; behavior identical to the previous commit.

* fix(bitflow-hodlmm-deposit): clarify active-bin coordinate systems in status preview

The status preview printed `observedActiveBinId` (BFF absolute, e.g. 646)
next to `routerExpectedBinId` (on-chain relative, e.g. 146) with no labels,
making the 500-bin center offset read as router-vs-BFF drift that would
revert at maxDeviation 0.

Verified against the live router (dlmm-liquidity-router-v-1-1
add-relative-liquidity-same-multi) and pool (dlmm-pool-sbtc-usdcx-v-1-bps-10):
the contract's ERR_ACTIVE_BIN_TOLERANCE assert compares its own on-chain
get-active-bin-id (returned 146) against the passed expected-bin-id (646-500=146),
so a synced pool yields delta 0 and passes even at maxDeviation 0. The offset is
by design (MIN_BIN_ID -500 / MAX_BIN_ID 500), not drift.

Rename fields to bffActiveBinId / onChainExpectedBinId and document the
coordinate systems so the broadcast path is not misdiagnosed as blocked.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: macbotmini-eng <macbotmini-eng@users.noreply.github.com>
Co-authored-by: biwasbhandari <biwas2059@gmail.com>
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants